package everything.search;

import everything.WorldMap;

public class SentryState {
	private int _x;
	private int _y;
	private String _direction;
	public SentryState(int oldX, int oldY, String direction, WorldMap map) {
		//TODO automaton can cause a bug if hes locked between 2 walls
		if (direction.equalsIgnoreCase("NORTH")){
			// turning south
			if (map.brickStatus(oldX - 1, oldY) == WorldMap.WALL){
				_x = oldX + 1;
				_y = oldY;
				_direction = "SOUTH";
			} else{  // going north
				_x = oldX - 1;
				_y = oldY;
				_direction = "NORTH";
			}
		} else if(direction.equalsIgnoreCase("SOUTH")){
			// turning north
			if (map.brickStatus(oldX + 1, oldY) == WorldMap.WALL){
				_x = oldX-1;
				_y = oldY;
				_direction = "NORTH";
			} else {  //going south
				_x = oldX+1;
				_y = oldY;
				_direction = "SOUTH";
			}
		} else if(direction.equalsIgnoreCase("WEST")){
			// turning east
			if (map.brickStatus(oldX , oldY - 1) == WorldMap.WALL){
				_x = oldX;
				_y = oldY+1;
				_direction = "EAST";
			} else{  // going west
				_x = oldX;
				_y = oldY-1;
				_direction = "WEST";
			}
		} else if(direction.equalsIgnoreCase("EAST")){
			// turning west
			if (map.brickStatus(oldX , oldY + 1) == WorldMap.WALL){
				_x = oldX;
				_y = oldY-1;
				_direction = "WEST";
			} else {  // going east
				_x = oldX;
				_y = oldY+1;
				_direction = "EAST";
			}
		} else {
			_x = 0;
			_y = 0;
			_direction = "HAHA";
		}
	}
	public int getX() {
		return _x;
	}
	public int getY() {
		return _y;
	}
	public String getDirection() {
		return _direction;
	}
}
